home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr49 / 141_01.zip / ROSE.C < prev    next >
Text File  |  1993-06-01  |  2KB  |  89 lines

  1. /* rose.c -- multi-petal drawing */
  2. /* 1984 apr 28 pmkrasno */
  3. #include "bdscio.h"
  4. #include "float.h"
  5. #define XSCALE "450.0" /* screen points, near full scale */
  6. #define YSCALE "450.0"
  7. #define WH 1    /* colors */
  8. #define BL 15
  9. #define NPTS 180
  10. #define wait pause () ; getchar () 
  11.  
  12. float pets[1], r[1] ;    /* extern */
  13.  
  14. main ()    {    /* calc x, y & plot */
  15.     float theta[2+NPTS], y[4+2*NPTS], delta ;
  16.     float *xcoord(), *ycoord() ;
  17.     float xscale[1], yscale[1], *maxx, *maxy ;
  18.     unsigned n, nfcns, npts, secs1, secs2 ;
  19.     int petals ;
  20.     byte time1[13], time2[13], time3[13] ;
  21.     byte dif12[13+5], dif23[13+5] ;
  22.  
  23.     nfcns = 2 ; /* # functions (x, y) */
  24.     maxx = TEN ;    maxy = TEN ;    /* OOPS */
  25.     atof (yscale, YSCALE) ;    atof (xscale, XSCALE) ;
  26.     fpdiv (delta, TWOPI, itof (delta, NPTS) ) ;
  27.     fpdiv (xscale, xscale, maxx) ;
  28.     fpdiv (yscale, yscale, maxy) ;
  29.     mode2 () ; cls (BL, WH) ;     npts = NPTS + 2 ;
  30.  
  31.     while (TRUE) {
  32.         do {    printf ("Petals (3-31) ? ") ;
  33.             scanf ("%d", &petals) ;
  34.             } while ( (petals < 3) 
  35.                 || (31 < petals) ) ;
  36.         itof (pets, petals) ;
  37.         syst_d (time1) ; 
  38.         printf ("Evaluate %3d points: %s\N", 
  39.             npts, time1) ;
  40.         comp_pts(npts, nfcns, theta, y, MHALFPI, 
  41.             delta, xcoord, ycoord) ;
  42.  
  43.         syst_d (time2) ;
  44.         printf ("Plot %3d points:     %s\N", 
  45.             npts, time2) ;
  46.         cls (WH, BL) ;
  47.         plot_lins (npts, nfcns-1, y, y+npts, 
  48.             xscale, yscale) ;
  49.  
  50.         syst_d (time3) ;
  51.         printf ("Done :               %s\N", time3) ;
  52.         secs1 = tim_dif (dif12, time2, time1) ;
  53.         secs2 = tim_dif (dif23, time2, time3) ;
  54.         /* convert differences to seconds */
  55.         printf ("Evaluate: %d secs; Plot: %d secs\N", 
  56.             secs1, secs2) ;
  57.     } /* forever */
  58. } /* main */
  59.  
  60. float *log (res, xin) float *res, *xin ;    {
  61.     int sign ;    float *log10 () ;
  62.     log10 (res, &sign, xin) ;
  63.     if ( sign < 0 ) fpchs (res, res) ;
  64.     return (res) ;
  65. } /* log */
  66.  
  67. float *xcoord (x, theta) float *x, *theta ;    {
  68.     float *sine(), *cosine(), t ; /* save r for y */
  69.     /* r = 1 + cos (n * theta) ;    */
  70.     /* x = r * sin (theta) ;    */
  71.     cosine (r, fpmult (t, pets, theta) ) ;
  72.     fpadd (r, ONE, r) ;
  73.     fpmult (x, sine (t, theta), r) ;
  74.     return x ;
  75. } /* xcoord */
  76.  
  77. float *ycoord (y, theta) float *y, *theta ;    {
  78.     float *sine(), *cosine(), t ; /* r saved by x */
  79.     /* r = 1 + cos (n * theta) ;     */
  80.     /* y = r * cos (theta) ;    */
  81.     fpmult (y, cosine (t, theta), r) ;
  82.     return y ;
  83. } /* ycoord */
  84.  
  85. ts, 
  86.             xscale, yscale) ;
  87.  
  88.         syst_d (time3) ;
  89.